﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Domain.Common;
using Domain.Map;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MapComponentSprite
{
    public class EmperorSprite : AutomatedSprite
    {
        /// <summary>
        /// 只有一个旗子图片，一个实例就可以了
        /// </summary>
        public static Texture2D EmperorImage { get; set; }

        public EmperorSprite()
        {
            if (EmperorImage == null)
                LoadPic();
            this.Image = EmperorImage;
        }
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Draw(this.Image,DrawPosition,null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0.8f);
        }

        public void Update(GameTime gameTime, Point position)
        {
            this.DrawPosition = new Rectangle(position.X, position.Y, MapUnit.Width, MapUnit.Height);
            Rectangle rectangle = new Rectangle();
            int xp = (int) (MapUnit.Width*0.5);//X坐标调节因子
            rectangle.X = (position.X) * MapUnit.Width + GameScreen.LeftEdge -xp ;
            rectangle.Y = (position.Y - 1) * MapUnit.Height + GameScreen.TopEdge;
            rectangle.Width = MapUnit.Width;
            rectangle.Height = MapUnit.Height;
            this.DrawPosition = rectangle;

        }

        public void LoadPic()
        {
            if (EmperorImage == null)
                EmperorImage = Game.Content.Load<Texture2D>(@"Images\buildings\type\huangdi");
        }
    }
}
